
//
// 101210 - AH - Created.
// 110108 - AH - Minor format.
//

package org.soekrat.engine.forest;

/**
 * <p>
 *   Mean of a 
 *   {@link Tree}'s distance with other
 *   {@link Tree}s in the table as computed by
 *   {@link TreeDistanceTable#getMeans()}.
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC)
 */
public final class Mean implements Comparable<Mean>
{
  /**
   * <p>
   *   {@link TreeDistanceTable} {@code this} is computed from.
   * </p>
   */
  public final TreeDistanceTable table;
  
  /**
   * <p>
   *   {@link Tree} with the distance mean.
   * </p>
   */
  public final Tree tree;
  
  /**
   * <p>
   *   {@link Tree}'s index in table.
   * </p>
   */
  public final int idx;
  
  /**
   * <p>
   *   Mean of 
   *   {@link Tree}'s distances to other trees in table.
   * </p>
   */
  public float mean;
  
  /**
   * <p>
   *   Constructor.
   * </p>
   * @param table {@link #table}.
   * @param tree  {@link #tree}.
   * @param idx   {@link #idx}.
   * @param mean  {@link #mean}.
   */
  Mean(TreeDistanceTable table, Tree tree, int idx, float mean)
  {
    this.table=table;
    this.tree=tree;
    this.idx=idx;
    this.mean=mean;
  }

  // Specified in Comparable<Mean>.
  public int compareTo(Mean o){ return Double.compare(mean, o.mean); }
  
  @Override
  public String toString() 
  {
    StringBuilder sb=new StringBuilder();
    
    sb.append("tree=").append(tree.getName()).append(",idx=")
      .append(idx).append(",mean=").append(mean);
    
    return sb.toString();
  }
  
  /**
   * <p>
   *   The empty array shared.
   * </p>
   */
  public static final Mean[] EMPTY_ARRAY=new Mean[0];
  
}
